<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://blogs">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="controls.xsl" />
	<xsl:include href="../comments/defaultList.xsl" />
	<xsl:include href="blocks.xsl" />
	<xsl:include href="blogsBars.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/blogs.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/comments.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/blogs.js" />
			<script type="text/javascript" src="{$baseURI}/js/baseComments.js" />
			<script type="text/javascript" src="{$baseURI}/js/blogsComments.js" />
			
			<xsl:comment>[if IE]&gt;&lt;link rel="stylesheet" href="<xsl:value-of select="$baseURI"/>/css/blogs-ie.css" type="text/css" media="all" /&gt;&lt;![endif]</xsl:comment>
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />
			
			<div id="header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div id="blocks">
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
					
					<div class="block">
						<h4>&labelBlockSimilar;</h4>
						<div>
							<xsl:apply-templates select="document(concat('xmodule://blogs/getSimilarPosts/', response/object/@id, ';', response/object/@type-id))/data/response" mode="block-similar-posts" />
						</div>
					</div>
					
					<div class="block">
						<h4>&labelBlockCloud;</h4>
						<div>
							<xsl:apply-templates select="document('xmodule://blogs/getTagsCloud')/data/response" mode="block-tags-cloud" />
						</div>
					</div>
					
					<div class="block">
						<h4>&labelBlockPopular;</h4>
						<div>
							<xsl:apply-templates select="document('xmodule://blogs/getBlogsBlock')/data/response" mode="block-blogs" />
						</div>
					</div>
				</div>
			</div>

			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		<xsl:apply-templates select="." mode="post" />
	</xsl:template>
	
	<xsl:template match="object[@type='article']" mode="post">
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="blogId" select="property[@name='blog_id']/value" />
		
		<xsl:if test="$blogId != '0'">
			<div id="blog_info">
				<xsl:apply-templates select="document(concat('xmodule://blogs/getBlog/', $blogId))/data/response/object" mode="blog-bar" />
			</div>
		</xsl:if>
		
		<xsl:if test="$blogId = '0'">
			<xsl:apply-templates select="document(concat('xobject://user/', property[@name='owner_id']/value))/data/object" mode="personal-blog-bar" />
		</xsl:if>
		
		<div class="post">
			<h1>
				<xsl:if test="property[@name='draft']/value = '1'">
					<img src="{$baseURI}/images/post-closed.png" title="&labelDraft;" alt="" />
					<xsl:text> </xsl:text>
				</xsl:if>
				<xsl:value-of select="property[@name='title']/value" disable-output-escaping="yes" />
			</h1>
			<div>
				<div class="post_body">
					<div class="post_body_inner">
						<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
					</div>
				</div>
				<div class="post_tags">
					<xsl:for-each select="property[@name='tags']/value">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="concat ($baseURI, '/blogs/tag/', .)" />
							</xsl:attribute>
							<xsl:value-of select="." />
						</a>
						<xsl:if test="position () != $countTags">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
				</div>
				<div class="post_info">
					<div class="post_info_inner">
						<xsl:call-template name="article-options" select="." />
					</div>
				</div>
			</div>
		</div>
		<xsl:if test="property[@name='published']/value = '1'">
			<a name="comments" />
			
			<h3 class="comments">&labelComments; (<xsl:value-of select="property[@name='count_comments']/value" />):</h3>
			
			<div id="comments_div">
				<xsl:apply-templates select="document(concat('xmodule://comments/getcomments/article;', @id))/data/response" mode="comments" />
			</div>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="object[@type='link']" mode="post">
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="blogId" select="property[@name='blog_id']/value" />
		
		<xsl:if test="$blogId != '0'">
			<div id="blog_info">
				<xsl:apply-templates select="document(concat('xobject://blog/', $blogId))/data/object" mode="blog-bar" />
			</div>
		</xsl:if>
		
		<xsl:if test="$blogId = '0'">
			<xsl:apply-templates select="document(concat('xobject://user/', property[@name='owner_id']/value))/data/object" mode="personal-blog-bar" />
		</xsl:if>
		
		<div class="post">
			<h1>
				<xsl:if test="property[@name='draft']/value = '1'">
					<img src="{$baseURI}/images/post-closed.png" title="&labelDraft;" alt="" />
					<xsl:text> </xsl:text>
				</xsl:if>
				<img src="{$baseURI}/images/post-link.png" alt="" />
				<xsl:text> </xsl:text>
				<xsl:value-of select="property[@name='title']/value" disable-output-escaping="yes" />
			</h1>
			<div>
				<div class="post_body">
					<div class="post_body_inner">
						<xsl:value-of select="property[@name='description']/value" disable-output-escaping="yes" />
					</div>
				</div>
				<div class="post_tags">
					<xsl:for-each select="property[@name='tags']/value">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="concat ($baseURI, '/blogs/tag/', .)" />
							</xsl:attribute>
							<xsl:value-of select="." />
						</a>
						<xsl:if test="position () != $countTags">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
				</div>
				<div class="post_info">
					<div class="post_info_inner">
						<xsl:call-template name="article-options" select="." />
					</div>
				</div>
			</div>
		</div>
		<xsl:if test="property[@name='published']/value = '1'">
			<a name="comments" />

			<h3 class="comments">&labelComments; (<xsl:value-of select="property[@name='count_comments']/value" />):</h3>

			<div id="comments_div">
				<xsl:apply-templates select="document(concat('xmodule://comments/getcomments/link;', @id))/data/response" mode="comments" />
			</div>
		</xsl:if>
	</xsl:template>
	
	<!-- BLOCK SIMILAR POSTS -->
	<xsl:template match="response" mode="block-similar-posts">
		<div id="similar_posts">
			<xsl:if test="count (object) = 0">
				<xsl:text>&labelSimilarEmpty;</xsl:text>
			</xsl:if>
			<xsl:apply-templates seelct="response" />
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type='article' or @type='link']">
		<xsl:param name="id" select="@id" />
		<xsl:param name="typeName" select="@type" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		<xsl:param name="blogAlias" select="property[@name='blog_alias']/value" />
		<xsl:param name="blogId" select="property[@name='blog_id']/value" />
		
		<div class="item">
			<span class="date">
				<xsl:value-of select="property[@name='pubdate']/value" disable-output-escaping="yes" />
			</span>
			<span class="arrow">→</span>
			<xsl:if test="$blogId = '0'">
				<a href="{$baseURI}/blogs/user/{$userLogin}" class="blog">
					<xsl:text>&labelBlogOf; </xsl:text>
					<xsl:value-of select="property[@name='user_name']/value" disable-output-escaping="yes" />
				</a>
			</xsl:if>
			<xsl:if test="$blogId != '0'">
				<a href="{$baseURI}/blog/{$blogAlias}" class="blog">
					<xsl:value-of select="property[@name='blog_title']/value" disable-output-escaping="yes" />
				</a>
			</xsl:if>
			<span class="arrow">→</span>
			<a href="{$baseURI}/post/{$typeName}/{$id}" class="post_title">
				<xsl:value-of select="property[@name='title']/value" disable-output-escaping="yes" />
			</a>
		</div>
	</xsl:template>
	
</xsl:stylesheet>